package com.zz.controller;

import com.alibaba.fastjson.JSONObject;
import com.zz.service.SignService;
import com.zz.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 合同模块 电子签章
@Slf4j
@RestController
@RequestMapping("/sign")
public class SignController {

    @Autowired
    SignService signService;

    @PostMapping("/electronicSignature")
    public ResultUtil electronicSignature(@RequestBody JSONObject jsonObject) {
        String contractId = jsonObject.getString("contractId");
        String operationId = jsonObject.getString("operationId");
        return signService.electronicSignature(contractId, operationId);
    }


    @PostMapping("/noticeDeveloperUrl")
    public String noticeDeveloper(@RequestBody String json) {
        // 接口e签宝的回调
        log.info("e签宝的合同回调json = " + json);
        /*
        e签宝的回调json = {"flowId":"e897e8056cbe4288afd3044151da8889","timestamp":1677216081709,"action":"PARTICIPANT_MARKREAD","accountId":"32160ce6ca574334b135872fbd856770","thirdPartyUserId":"152104199402251213","order":1,"readTime":"2023-02-24 13:21:21"}
        e签宝的回调json = {"action":"SIGN_FLOW_UPDATE","flowId":"e897e8056cbe4288afd3044151da8889","accountId":"32160ce6ca574334b135872fbd856770","authorizedAccountId":"32160ce6ca574334b135872fbd856770","order":1,"signTime":"2023-02-24 13:22:11","signResult":2,"resultDescription":"签署完成","thirdPartyUserId":"152104199402251213","timestamp":1677216131264}
        e签宝的回调json = e签宝的回调json = {"action":"SIGN_FLOW_FINISH","flowId":"96ae395fc3c040029e1133a56167a98b","businessScence":"zb盐酸纳美芬注射液1ml-0.1mg - 5支-盒.PDF","flowStatus":"2","createTime":"2023-02-24 13:42:50","endTime":"2023-02-24 13:43:46","statusDescription":"完成","timestamp":1677217427206}
       */
        signService.noticeDeveloper(json);

        return "{\"code\":\"200\",\"msg\":\"success\"}";
    }

    @GetMapping("/test")
    public void test(@RequestParam("contractId") String contractId) {
        signService.updateSaleTarget(contractId);
    }

}
